<?php
  
  function cekTypeImageUpload($typeImage){
	   $hasil = 0;  // kondisikan terlebih dahulu kalau image benar
	   $tipe = $typeImage;
	   if ($tipe != "image/jpeg" and $tipe != "image/pjpeg") {
		  $hasil = 1; // kondisi image salah
	   }
	   
	   return $hasil;
  }
  
  function cekDimensiMax($lokasi_file){
       $lebar_max 		= 2200;
	   $tinggi_max 		= 1300;
	   $lokasi_gambar 	= $lokasi_file;
	   $hasil			= 0;
	   
	   $ukuran_asli = GetImageSize($lokasi_gambar);
	   
	   if ( $ukuran_asli[0] > $lebar_max  or $ukuran_asli[1] > $tinggi_max ) {
		 $hasil = 1;
	   }
	   
	   return $hasil;
  }
  
  function cekDimensiMin($lokasi_file){
       $lebar_min 		= 100;
	   $tinggi_min 		= 125;
	   $lokasi_gambar 	= $lokasi_file;
	   $hasil			= 0;
	   
	   $ukuran_asli = GetImageSize($lokasi_gambar);
	   
	   if ( $ukuran_asli[0] < $lebar_min  or $ukuran_asli[1] < $tinggi_min ) {
	      $hasil = 1;
	   }
	   
	   return $hasil;
  }
  
  
  function thumbnailImage ($nama_file, $direktori, $tipe_file) {
    $d = "server/php/files/";
	$image_asli	 = $d . $nama_file;
	
	if ($tipe_file == "image/jpeg"){
		$gambar_asli = imagecreatefromjpeg($image_asli);
		$lebar 		 = imageSX($gambar_asli);
		$tinggi 	 = imageSY($gambar_asli);
		
		$tmb_lebar   = 300;
		$tmb_tinggi  = 300;
		
		$image_tmb   = imagecreatetruecolor($tmb_lebar,$tmb_tinggi);
		imagecopyresampled($image_tmb,$gambar_asli,0,0,0,0,$tmb_lebar,$tmb_tinggi,$lebar,$tinggi);
		
		imagejpeg($image_tmb,$d . "small_" . $nama_file);
	
	}else{
		$gambar_asli = imagecreatefrompng($image_asli);
		$lebar 		 = imageSX($gambar_asli);
		$tinggi 	 = imageSY($gambar_asli);
		
		$tmb_lebar   = 220;
		$tmb_tinggi  = 242;
		
		$image_tmb   = imagecreatetruecolor($tmb_lebar,$tmb_tinggi);
		imagecopyresampled($image_tmb,$image_asli,0,0,0,0,$tmb_lebar,$tmb_tinggi,$lebar,$tinggi);
		imagepng($image_tmb,$d . "small_" . $nama_file);
	
	}
	
	imagedestroy($gambar_asli);
	imagedestroy($image_tmb);
	
	return $image_asli;
  } 
  
  
  function koneksi_db() {
    $host     = "localhost";
	$database = "amicta";
	$user     = "root";
	$password = "";
	
	$link = mysql_connect($host,$user,$password);
	
	mysql_select_db($database,$link);
	
	if(!$link){
	  echo "error : ".mysql_error();
	}
	
	return $link;
  }
  
  function cekEmailSama($m){
    $mail = $m;
    $link = koneksi_db();
	$sql = "select * from member where email='$mail'";
	$res = mysql_query($sql,$link);
	$jml = mysql_num_rows($res);
	$hasil = 0;
	
	if ($jml>0) {
	  $hasil = 1;
	}
	
	return $hasil;
  }
  
  function get_judul_produk($id){
	$koneksi2 = koneksi_db();
	$sql2 = "select * from produk where idproduk='$id'";
	$q2  = mysql_query($sql2,$koneksi2);
	$f2  = mysql_fetch_array($q2);
	
	return $f2['judul'];
  }
  
  function konversi_bulan($bulan){
  	switch($bulan){
  		case "January" : return "01";break;
  		case "February" : return "02";break;
  		case "March" : return "03";break;
  		case "April" : return "04";break;
  		case "May" : return "05";break;
  		case "June" : return "06";break;
  		case "July" : return "07";break;
  		case "August" : return "08";break;
  		case "September" : return "09";break;
  		case "October" : return "10";break;
  		case "November" : return "11";break;
  		case "December" : return "12";break;
  	}
  }
?>